package org.tuproj.drujbapizza;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class PizzaDetailActivity extends Activity {
	private TextView pizzaTitle;
	private TextView pizzaPrice;
	private TextView pizzaDescription;
	private ArrayList<Pizza> list;

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		getActionBar().setDisplayHomeAsUpEnabled(true);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pizza_detail);

		pizzaTitle = (TextView) findViewById(R.id.txtPizzaTitle);
		pizzaPrice = (TextView) findViewById(R.id.txtPrice);
		pizzaDescription = (TextView) findViewById(R.id.txtPizzaDescription);
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			list = (ArrayList<Pizza>) extras.get("CURRENT_PIZZA_LIST");
			int currentPizzaIndex = extras.getInt("PIZZA_INDEX");
			Pizza pizza = list.get(currentPizzaIndex);
			Log.i("Choosed Pizza in Detail", pizza.toString());
			pizzaTitle.setText(pizza.getName());
			pizzaPrice.setText("Price:" + Double.valueOf(pizza.getPrice()));
			pizzaDescription.setText(pizza.getDescription());

		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_pizza_detail, menu);
		return true;
	}

	public void orderPizza(View v) {
		startActivity(new Intent(this, PizzaOrderActivity.class));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			Intent intent = new Intent(this, PizzaMenuActivity.class);
			intent.putParcelableArrayListExtra("CURRENT_PIZZA_LIST",list);
			startActivity(intent);
		}

		return super.onOptionsItemSelected(item);
	}
}
